<%@ page import="java.util.*" %>

<jsp:useBean id="cart" scope="session" class="pl.webshop.Cart" />
<html>
	<head>
		<title>Koszyk</title>
	</head>
	<body>
		<%
		String username =  (String)session.getAttribute("username");  
 		if(username == null)
  		{ 
			response.sendRedirect("login.jsp");
  		}
		%>
		<div align="center">
			<% int itemsBought = cart.checkBuy(request); %>
			<table border="1">
			<caption><b>Zawartosc koszyka</b></caption>
			<tr>
				<th>Produkt</th>
				<th>Cena</th>
				<th>Ilosc</th>
			</tr>
			<%
			Enumeration e = cart.getElements();
			String[] Item;
			
			while (e.hasMoreElements()) 
			{
				Item = (String[])e.nextElement();
		 	%>
			<tr>
				<td><%=Item[1] %></td>
				<td align="center">$<%=Item[2] %></td>
				<td align="center"><%=Item[3] %></td>
			</tr>
			<%
			}
			%> 
			</table>
			<p>Calkowity koszt: <%=cart.getCost() %>$</p>
			<% if(cart.getNumOfItems() != 0 )
			{
			%>
			<form action="cart.jsp" method="post">
				<input type="submit" name="Buy" value="Buy">
			</form>
			<%
			} 
			else if(itemsBought > 0)
			{
				out.write("<p>Zakupiono: " + itemsBought + " rzeczy.</p>");
			}
			%>
		</div>
		<a href="main.jsp">Powrot do katalogu</a>
	</body>
</html>

